package com.lixin.web.webSocket.impl;

import cn.hutool.core.util.StrUtil;
import com.lixin.entity.Posts;
import com.lixin.model.request.PostListRequest;
import com.lixin.model.response.Response;
import com.lixin.service.IPostsService;
import com.lixin.web.netty.NettyUtil;
import com.lixin.web.webSocket.PostsManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Description:
 * Copyright:   Copyright (c)2023
 * Company:     sci
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2023-08-12 22:18:27
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2023-08-12     张李鑫                     1.0         1.0 Version
 */
@Service("posts")
public class PostsManagerImpl implements PostsManager {

    public static final Integer DEFAULT_POST_PAGE_SIZE = 10;

    @Autowired
    private IPostsService postsService;

    /**
     * 简单做一个动态存储功能
     * 其实还有很多拓展的余地 比如提醒用户
     *
     * @param posts
     * @return
     */
    @Override
    public Response<Object> SendPost(Posts posts) {
        if (StrUtil.isEmpty(posts.getContent())) {
            return Response.error("content isEmpty ");
        }
        posts.setUserId(NettyUtil.getUserId());
        return Response.success(postsService.addOrUpdate(posts));
    }

    /**
     * 朋友圈查询不是普通的分页 他应该是刷新到某个动态以后在向下继续请求往前的pageSize
     *
     * @return
     */
    @Override
    public Response<List<Posts>> postList(PostListRequest postListRequest) {
        return Response.success(postsService.postList(NettyUtil.getUserId(),postListRequest.getCurPostId()));
    }


}
